home *** CD-ROM | disk | FTP | other *** search
- #import <appkit/appkit.h>
- #import <3Dkit/3Dkit.h>
-
- // here's the deal. Given a bounding box, we're going to transform that
- // by the given transformation matrix. Since this effects the extent
- // of the object, we have to transform all 8 points of the bounding box.
- // After transforming them, we then redetermine the min and max of things
- // orthogonal to the current origin.
- // it's fine if newBB and aBB point to the same boundingBox...
-
- // really should look at Arvo's Gem, p 548 of GG1...
-
- void
- WW3DDetermineBoundGivenBoundAndCTM(RtBound *newBB, RtBound *aBB, RtMatrix aCTM)
- {
- RtPoint bboxPoints[8], bboxPointsTransformed[8];
- int i;
-
-
- N3D_XComp(bboxPoints[0]) = (*aBB)[0];
- N3D_YComp(bboxPoints[0]) = (*aBB)[2];
- N3D_ZComp(bboxPoints[0]) = (*aBB)[4];
-
- N3D_XComp(bboxPoints[1]) = (*aBB)[1];
- N3D_YComp(bboxPoints[1]) = (*aBB)[2];
- N3D_ZComp(bboxPoints[1]) = (*aBB)[4];
-
- N3D_XComp(bboxPoints[2]) = (*aBB)[0];
- N3D_YComp(bboxPoints[2]) = (*aBB)[3];
- N3D_ZComp(bboxPoints[2]) = (*aBB)[4];
-
- N3D_XComp(bboxPoints[3]) = (*aBB)[1];
- N3D_YComp(bboxPoints[3]) = (*aBB)[3];
- N3D_ZComp(bboxPoints[3]) = (*aBB)[4];
-
- N3D_XComp(bboxPoints[4]) = (*aBB)[0];
- N3D_YComp(bboxPoints[4]) = (*aBB)[2];
- N3D_ZComp(bboxPoints[4]) = (*aBB)[5];
-
- N3D_XComp(bboxPoints[5]) = (*aBB)[1];
- N3D_YComp(bboxPoints[5]) = (*aBB)[2];
- N3D_ZComp(bboxPoints[5]) = (*aBB)[5];
-
- N3D_XComp(bboxPoints[6]) = (*aBB)[0];
- N3D_YComp(bboxPoints[6]) = (*aBB)[3];
- N3D_ZComp(bboxPoints[6]) = (*aBB)[5];
-
- N3D_XComp(bboxPoints[7]) = (*aBB)[1];
- N3D_YComp(bboxPoints[7]) = (*aBB)[3];
- N3D_ZComp(bboxPoints[7]) = (*aBB)[5];
-
- N3DMult3DPoints(bboxPoints, 8, aCTM, bboxPointsTransformed);
-
- // start off setting newBB to be the first point
- (*newBB)[0] = (*newBB)[1] = N3D_XComp(bboxPointsTransformed[0]);
- (*newBB)[2] = (*newBB)[3] = N3D_YComp(bboxPointsTransformed[0]);
- (*newBB)[4] = (*newBB)[5] = N3D_ZComp(bboxPointsTransformed[0]);
-
- for (i = 1; i < 8; i++)
- { //// X
- if ((*newBB)[0] > N3D_XComp(bboxPointsTransformed[i]))
- { (*newBB)[0] = N3D_XComp(bboxPointsTransformed[i]);
- }
- if ((*newBB)[1] < N3D_XComp(bboxPointsTransformed[i]))
- { (*newBB)[1] = N3D_XComp(bboxPointsTransformed[i]);
- }
- //// Y
- if ((*newBB)[2] > N3D_YComp(bboxPointsTransformed[i]))
- { (*newBB)[2] = N3D_YComp(bboxPointsTransformed[i]);
- }
- if ((*newBB)[3] < N3D_YComp(bboxPointsTransformed[i]))
- { (*newBB)[3] = N3D_YComp(bboxPointsTransformed[i]);
- }
- //// Z
- if ((*newBB)[4] > N3D_ZComp(bboxPointsTransformed[i]))
- { (*newBB)[4] = N3D_ZComp(bboxPointsTransformed[i]);
- }
- if ((*newBB)[5] < N3D_ZComp(bboxPointsTransformed[i]))
- { (*newBB)[5] = N3D_ZComp(bboxPointsTransformed[i]);
- }
- }
-
- return ;
- }
-
-